﻿@{
    
    ViewBag.Title = "Site Resources Manager";
}
<style type="text/css">
    .t-grid td
    {
        line-height: 10px;
    }
</style>
<h2>
    Webinar</h2>
<div>
    @(Html.Telerik().Grid<Century.Models.Common.GenericNews>()
                .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.Id))
                .ToolBar(commands =>
                {
                    commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" });
                })
        .Columns(columns =>
        {
            columns.Bound(o => o.Id).Hidden().ReadOnly(true);
            columns.ForeignKey(o => o.CountrySiteId, (System.Collections.IEnumerable)ViewBag.AccessibleSites, "Id", "Name").Sortable(true).Width(150).Title("Country").ReadOnly(true);

            columns.Bound(o => o.WebinarLink).EditorTemplateName("MultiLineEditor").Width(350);
            columns.Bound(o => o.Details).Title("Subject");
            //columns.Bound(o => o.Details).ClientTemplate("<#=Details#>");//.HtmlAttributes(new {@class="testclass"}).Width(600);
            columns.Bound(o => o.PublishDate).EditorTemplateName("DateTime").Sortable(true).Title("Date");
            columns.Bound(o => o.IsActive).Hidden(true);
            columns.ForeignKey(o => o.GenericNewsTypeId, (System.Collections.IEnumerable)ViewBag.GenericNewsType, "Id", "Name").Width(150).Sortable(true).Title("Generic News Type").Hidden(true).Visible(false);

            columns.Command(command =>
            {
                command.Edit().ButtonType(GridButtonType.ImageAndText);
                command.Delete().ButtonType(GridButtonType.ImageAndText);
            }).Width(180);
        })
         .ClientEvents(clientEvents =>
         {

             clientEvents.OnEdit("editClick");
         })
        .DataBinding(dataBinding => dataBinding.Ajax()
                                     .Select("GetWebinarList", "GenericNews")
                                     .Update("UpdateWebinar", "GenericNews")
                                     .Insert("InsertWebinar", "GenericNews")
                                     .Delete("DeleteWebinar", "GenericNews")
         )
            .Groupable()
            .Editable(editing => editing.Mode(GridEditMode.PopUp).FormHtmlAttributes(new { style = "width:200px" }))
            .Pageable(pagingSetting => pagingSetting.PageSize(30))
            .Sortable(sortable => sortable.OrderBy(order => order.Add(o => o.CountrySite.Path).Descending()))
            .Scrollable(c => c.Height("550px"))
            .Resizable(config =>
                         {
                             config.Columns(true);
                         })
                        .Reorderable(config =>
                         {
                             config.Columns(true);
                         })
                        .ColumnContextMenu()
    )
</div>
<script type="text/javascript">
    function editClick(e) {
        $('.t-html').click('Details', showHtml);
        $(e.form).closest(".t-window-content").width(650).height(520);
        var popup = $("#" + e.currentTarget.id + "PopUp");
        popup.css({ "left": ($(window).width() / 2 - $(popup).width() / 2) + "px", "top": ($(window).height() / 2 - $(popup).height() / 2) + "px" });

        $('.editor-label:eq(0)').text('Country');       
        $('.editor-label:eq(2)').text('Subject');
        $('.editor-label:eq(3)').text('Date');
        $('.editor-label:eq(5)').hide();
        $('.editor-label:eq(4)').hide();
        $('.editor-field:eq(5)').hide();
        $('.editor-field:eq(4)').hide();
        $('.editor-field:eq(1)').hide();
        $('.editor-label:eq(1)').hide();
    }


</script>
<script type="text/javascript">
    function onDropDownListChange(e) {

        $.ajax({
            type: "post",
            url: '@Url.Action("CountrySiteChange", "CountrySiteSelector")',
            data: { selectedCountrySiteId: e.value
            },
            dataType: "html",
            success: function (msg) {
                $("#Grid").data("tGrid").rebind();
            },
            error: function (msg) {
                alert('Error on changing country site');
            }
        });


    }
</script>
